package com.haiqi.modules.map.web;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.BaseController;
import com.haiqi.common.annotation.SafeAuthority;
import com.haiqi.common.bean.DataGridBean;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.entity.CompanyWarning;
import com.haiqi.common.utils.PageUtils;
import com.haiqi.modules.main.bean.ResponseBean;
import com.haiqi.modules.map.service.CompanyWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hythzx on 2016/6/28.
 */

@RequestMapping("/manage/map/company/warning")
@Controller
@SafeAuthority(menuCode = "monitorLocation,companyMonitorLocation")
public class CompanyWarningController extends BaseController {

    @Autowired
    private CompanyWarningService companyWarningService;

    @Value("${geo.server}")
    private String geoServer;

    @RequestMapping("/save")
    @ResponseBody
    public Map save(CompanyWarning companyWarning, String wkt, HttpSession session){
        companyWarning.setCoordinates(wkt);
        ResponseBean.UserBean user = getUser(session);
        companyWarning.setCompany(user.getOfficeid());
        boolean success = companyWarningService.save(companyWarning);
        Map map = new HashMap();
        map.put("result",success);
        map.put("guid",companyWarning.getGuid());
        return map;
    }

    @ResponseBody
    @RequestMapping("/delete")
    public Map delete(CompanyWarning companyWarning){
        boolean  success = companyWarningService.delete(companyWarning);
        Map map = new HashMap();
        map.put("result",success);
        return map;
    }

    @ResponseBody
    @RequestMapping("/ajax/data/list")
    public List<CompanyWarning> getDataList(CompanyWarning companyWarning, HttpSession session){
        ResponseBean.UserBean user = getUser(session);
        companyWarning.setCompany(user.getOfficeid());
        List<CompanyWarning> dataList = companyWarningService.getDataList(companyWarning);
        return dataList;
    }

    @ResponseBody
    @RequestMapping("/ajax/data/page/list")
    public DataGridBean<CompanyWarning> getPageDataList(CompanyWarning companyWarning, PageBean page, HttpSession session){
        PageUtils.generatePage(page);
        ResponseBean.UserBean user = getUser(session);
        companyWarning.setCompany(user.getOfficeid());
        List<CompanyWarning> dataList = companyWarningService.getDataList(companyWarning);
        PageInfo<CompanyWarning> pageInfo = new PageInfo<>(dataList);
        DataGridBean<CompanyWarning> mobileShipDataGridBean = new DataGridBean<>();
        PageUtils.convertToEasyuiList(pageInfo, mobileShipDataGridBean);
        return mobileShipDataGridBean;
    }


}
